export const asyncTimeoutUtil = (timeout = 2 * 1000, targetPromise: Promise<any>): Promise<any> => {

  let abortFn: Function;

  const abortPromise = new Promise(function (_, reject) {
    abortFn = function () {
      reject();
    }
  });

  const promiseRaceResult = Promise.race([
    targetPromise,
    abortPromise
  ]);

  const to = setTimeout(function () {
    abortFn?.();
    clearTimeout(to);
  }, timeout);

  return promiseRaceResult;
}
